package main

import (
	"fmt"
	"strings"
)

func splitWord(str string, downStream chan string) {
	strArr := strings.Fields(str)
	for _, value := range strArr {
		downStream <- value
	}
	close(downStream)
}

func filter(upStream, downStream chan string) {
	wordMap := make(map[string]int)
	for item := range upStream {
		if wordMap[item] == 0 {
			wordMap[item]++
			downStream <- item
		}
	}
	close(downStream)
}

func print(upStream chan string) {
	for item := range upStream {
		fmt.Println(item)
	}
}

func main() {
	c0, c1 := make(chan string), make(chan string)
	str := "Travelling around ChinaTravelling around China can be tiring but fun as well. However, how you travel often determines whether your travel will be a success or a failure"
	go splitWord(str, c0)
	go filter(c0, c1)
	print(c1)
}
